﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Controls_SHANGPINCOLUMN : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
        }
    }

    #region 可选分类


    public void Bind(string spdm)
    {
        Hid_ColumnList.Value = spdm;
        LBX_choose.Items.Clear();
        LBX_Sum.DataSource = new BLL.SHANGPIN().GetSPCOMMODITY_TYPEList2().Tables[0].DefaultView;
        LBX_Sum.DataTextField = "CT_NAME";
        LBX_Sum.DataValueField = "CT_CODE";
        LBX_Sum.DataBind();

        DataSet ds=new BLL.COMMODITY_CT().GetList(spdm);
        LBX_choose.DataSource = ds.Tables[0].DefaultView;
        LBX_choose.DataTextField = "CT_NAME";
        LBX_choose.DataValueField = "CT_CODE";
        LBX_choose.DataBind();
    }
    #endregion

    #region 添加扩展分类
    protected void Btn_ExTColumn_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        List<Model.COMMODITY_CT> cct = new List<Model.COMMODITY_CT>();
        for (int i = 0; i < LBX_choose.Items.Count; i++)
        {
            Model.COMMODITY_CT cc = new Model.COMMODITY_CT();
            cc.CCT_CMODCODE = Hid_ColumnList.Value;
            cc.CCT_COMDTYPECODE = LBX_choose.Items[i].Value;
            cct.Add(cc);
        }
        try
        {
            new BLL.COMMODITY_CT().Delete(Hid_ColumnList.Value);
            new BLL.COMMODITY_CT().Add(cct);
        }
        catch
        {
            Share.Alert(this.Page,"操作失败"); return;
        }
    }
    #endregion



    protected void Button3_ServerClick1(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        for (int i = 0; i < LBX_Sum.Items.Count; ++i)
        {
            if (LBX_Sum.Items[i].Selected)
            {
                ListItem li = new ListItem(LBX_Sum.Items[i].Text, LBX_Sum.Items[i].Value);
                //if (!new BLL.SHANGPIN().CheckSPColumnISLeaf(LBX_Sum.Items[i].Value))
                //{
                //    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('所选结点不是叶子结点!')", true);
                //    return;
                //}
                if (!LBX_choose.Items.Contains(li))
                {
                    LBX_choose.Items.Add(li);
                }
            }
        }
    }
    protected void Button4_ServerClick1(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        for (int i = 0; i < LBX_choose.Items.Count; i++)
        {
            if (LBX_choose.Items[i].Selected)
            {
                LBX_choose.Items.Remove(LBX_choose.Items[i]);
            }
        }
    }
}
